package com.xuanyuan.viewfunc.mask

import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import com.alibaba.android.arouter.facade.annotation.Route
import com.xuanyuan.base.BaseActivity
import com.xuanyuan.viewfunc.R
import com.xuanyuan.viewfunc.databinding.ActivityImageMaskBinding

/**
 * Copyright (C), 2017-2022, Anker
 * FileName: ImageMaskActivity  View蒙层
 *
 * @author ken.luo
 * Date: 2022/6/3 17:27
 * Description: 常见的ImageView蒙层方式
 * History:
 * 创建者 : ken.luo
 * <author>     <time>     <version>      <desc>
 * 作者姓名      修改时间      版本号          描述
</desc></version></time></author> */
@Route(path = "/common/activity/list")
class ImageMaskActivity : BaseActivity<ActivityImageMaskBinding>(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding.click = this

        mBinding.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                val count: Int = ((progress / 100.0f) * 100).toInt()
                val percent = count / 100.0f
                mBinding.tvSeekBar.text = ("$count %")
                val colorMatrix = ColorMatrix()
                colorMatrix.setSaturation(percent)
                val colorFilter = ColorMatrixColorFilter(colorMatrix)
                mBinding.image.colorFilter = colorFilter
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })

    }

    override fun initLayout(): Int {
        return R.layout.activity_image_mask
    }

    override fun afterInit() {

    }


    override fun onClick(v: View?) {
        if (v == null) {
            return
        }

        when (v) {
            mBinding.btnColor1 -> {
                mBinding.image.setColorFilter(resources.getColor(R.color.color10))
            }
            mBinding.btnColor2 -> {
                mBinding.image.setColorFilter(resources.getColor(R.color.color20))
            }
            mBinding.btnColor3 -> {
                mBinding.image.setColorFilter(resources.getColor(R.color.color30))
            }
            mBinding.btnColor4 -> {
                mBinding.image.setColorFilter(resources.getColor(R.color.color40))
            }
            mBinding.btnColor5 -> {
                mBinding.image.setColorFilter(resources.getColor(R.color.color50))
            }
        }

    }


}